package com.github.iot.view.drag;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

/**
 * TODO
 *
 * @Author: 梁声洪
 * @Date: 2019/12/9 22:41
 * @Version: v1.0.0
 */
public class DragForScrollView extends ScrollView {

    private boolean isDrag;

    public DragForScrollView(Context context) {
        super(context);
    }

    public DragForScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DragForScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN || ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE) {
            if (isDrag) {
                return false;
            }
        }
        return super.onInterceptTouchEvent(ev);
    }

    public void startDrag(int position) {
        isDrag = true;
    }

    public void endDrag(int position) {
        isDrag = false;
    }

}